﻿
@{
    Layout = null;
    ViewBag.Title = "登录";
}
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title></title>
    <link href="~/css/aui.2.0.css" rel="stylesheet" />
    <link href="~/css/aui-slide.css" rel="stylesheet" />
    <link href="~/css/aui-pull-refresh.css" rel="stylesheet" />
    <link href="~/css/aui-index.css" rel="stylesheet" />
    <link href="~/css/aui-login.css" rel="stylesheet" />
    <link href="~/css/common.css" rel="stylesheet" />
    @Scripts.Render("~/bundles/jquery")
</head>
<body>

    <section class="aui-content">
        <div class="aui-card-list aui-border-t aui-border-b aui-card-red">
            <div class="aui-card-list-content-padded aui-card-list-content-img-pd">
                <img src="~/image/zu.png" alt="头像" />
            </div>
            <div class="aui-card-list-hearder-pd">
                山海天党建平台
            </div>
            <div>
    </section>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-form-list aui-form-list-ul" style="">
            <li class="aui-list-item">
                <input id="UserName" type="text" placeholder="请输入用户名" />
            </li>
            <li class="aui-list-item">
                <input id="UserPwd" type="password" placeholder="请输入密码" />
            </li>
        </ul>
    </div>
    <div class="aui-btn aui-btn-block">登录</div>

    <!--加载动画Start-->
    <div id="loading">
        <div class="loading">
            <img src="~/image/loading.gif" />
        </div>
    </div>
    <!--加载动画End-->

    <script type="text/javascript" src="~/Scripts/api.js"></script>
    <script src="~/Scripts/aui-dialog.js"></script>
    <script type="text/javascript">
        apiready = function () {
        }

        var dialog = new auiDialog({});

        $(function () {

            //隐藏加载动画
            $("#loading").hide();
            $(".aui-btn").click(function () {
                //获取数据
                var UserName = $("#UserName").val();
                var UserPwd = $("#UserPwd").val();

                //验证
                if (UserName == "") {
                    //对话框
                    dialog.alert({
                        title: "消息提示",
                        msg: "请输入用户名！",
                        buttons: ['确定']
                    }, function (ret) {
                        console.log(ret)
                    });
                    return;
                }

                if (UserPwd == "") {
                    //对话框
                    dialog.alert({
                        title: "消息提示",
                        msg: "请输入密码！",
                        buttons: ['确定']
                    }, function (ret) {
                        console.log(ret)
                    });
                    return;
                }

                //显示加载动画
                $("#loading").show();

                $.ajax({
                    url: "http://shtdj.shanhaitian.gov.cn/AppInterface/api/User/Login",
                    type: "POST",
                    contentType: "application/json",
                    async: true,
                    data: JSON.stringify({ UserName: UserName, UserPwd: UserPwd }),
                    success: function (data, status) {
                        var dd = eval(data);
                        if (dd.code == "201") {
                            //对话框
                            dialog.alert({
                                title: "消息提示",
                                msg: dd.msg,
                                buttons: ['确定']
                            }, function (ret) {
                                console.log(ret);
                                $("#loading").hide();
                            });
                        }
                        else if (dd.code == "400") {
                            //对话框
                            dialog.alert({
                                title: "消息提示",
                                msg: dd.msg,
                                buttons: ['确定']
                            }, function (ret) {
                                console.log(ret);
                                $("#loading").hide();
                            });
                        }
                        else if (dd.code == "200") {

                            //存储Session
                            $.ajax({
                                url: "@Url.Action("SetSession")",
                                type: "POST",
                                contentType: "application/json",
                                async: true,
                                data: JSON.stringify({ model: dd.result }),
                                success: function (data, status) {
                                    var cc = eval(dd);
                                    if (cc.code == "200") {
                                        //跳转到个人中心
                                        window.location.href = "@Url.Action("PersonCenter")";
                                    }
                                    else {
                                        //对话框
                                        dialog.alert({
                                            title: "消息提示",
                                            msg: "请重新登录！",
                                            buttons: ['确定']
                                        }, function (ret) {
                                            console.log(ret);
                                            $("#loading").hide();
                                        });
                                    }
                                },
                                error: function (xhr, textStatus) {
                                    console.log('错误')
                                    console.log(xhr)
                                    console.log(textStatus)
                                }
                            });
                        }
                    },
                    error: function (xhr, textStatus) {
                        console.log('错误')
                        console.log(xhr)
                        console.log(textStatus)
                    }
                });
            });
        });

    </script>
</body>
</html>
